Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove allocations in callbacks #230

Merged
merged 12 commits into from
Oct 24, 2022
Merged

Remove allocations in callbacks #230

merged 12 commits into from
Oct 24, 2022

Conversation

frapac
Copy link
Collaborator

@frapac frapac commented Oct 7, 2022

  • add PrimalVector abstraction to remove the need to use _madnlp_unsafe_wrapper
  • rework KKT system to pass only the Jacobian w.r.t. the original variable x (without the slack)

@frapac frapac requested a review from sshin23 October 7, 2022 17:02
@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2022

Codecov Report

Merging #230 (dbef23c) into master (be4f87e) will decrease coverage by 0.02%.
The diff coverage is 95.87%.

@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
- Coverage   74.31%   74.29%   -0.03%     
==========================================
  Files          38       38              
  Lines        3703     3727      +24     
==========================================
+ Hits         2752     2769      +17     
- Misses        951      958       +7     
Impacted Files Coverage Δ
src/IPM/utils.jl 93.47% <ø> (ø)
src/IPM/callbacks.jl 92.04% <80.55%> (-7.96%) ⬇️
src/IPM/solver.jl 91.44% <98.07%> (+0.05%) ⬆️
src/IPM/IPM.jl 98.87% <100.00%> (+0.06%) ⬆️
src/IPM/kernels.jl 84.16% <100.00%> (ø)
src/IPM/restoration.jl 100.00% <100.00%> (ø)
src/KKT/rhs.jl 89.36% <100.00%> (+2.18%) ⬆️
src/KKT/sparse.jl 99.33% <100.00%> (+0.02%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@sshin23 sshin23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @frapac! It overall looks great! I only have a few comments

x_nlpmodel = _madnlp_unsafe_wrap(x, get_nvar(nlp))
hess_nlpmodel = _madnlp_unsafe_wrap(hess, get_nnzh(nlp.meta))
scale = (get_minimize(nlp) ? one(T) : -one(T))
scale *= (is_resto ? zero(T) : solver.obj_scale[])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale = is_resto ? zero(T) : get_minimize(nlp) ? one(T) : -one(T)

@test n_allocs == 0
n_allocs = @allocated MadNLP.eval_lag_hess_wrapper!(solver, kkt, x, solver.y)
@test n_allocs == 0
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice! maybe in the future we can do it for the whole solver level

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! we should at least apply the same test on the linear solver wrapper.

@@ -7,6 +7,7 @@ Implement the [`AbstractReducedKKTSystem`](@ref) in sparse COO format.
"""
struct SparseKKTSystem{T, VT, MT} <: AbstractReducedKKTSystem{T, VT, MT}
hess::VT
jac_callback::VT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

@sshin23 sshin23 merged commit 15c227e into master Oct 24, 2022
@frapac frapac deleted the fp/alloc_callbacks branch May 31, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants